#include <func.h>

int recvCycle(int sockFd, void *buf, int totalLen){
    //接收完total个字节才结束接收
    int recvRet = 0;    //当次recv
    int recvLen = 0;    //目前已接收的长度

    while(recvLen < totalLen){
        recvRet = recv(sockFd, (char*)buf + recvLen, totalLen - recvLen, 0);
        if(recvRet == 0){
            //对端关闭了
            printf("server exit!\n");
            return -1;
        }
        recvLen += recvRet;
    }

    return recvLen;
}
